package com.gsmr.controller;

import java.io.Console;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;

import com.gsmr.service.InterferenceQueryService;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.Workbook;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import com.gsmr.entity.AlarmInfo;
import com.gsmr.entity.Interference;
import com.gsmr.entity.PageBean;
import com.gsmr.entity.Serverinfo;
import com.gsmr.service.AlarmInfoService;
import com.gsmr.service.ServerStateService;
import com.gsmr.util.ExcelUtil;
import com.gsmr.util.FormatDate;
import com.gsmr.util.JsonUtil;
import com.gsmr.util.PropertityUtil;
import com.gsmr.util.ResponseUtil;
import com.gsmr.util.StringUtil;

import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

/**
 * @author 作者 : 黄志新
 * @version 创建时间：2017年8月11日 上午12:13:57 类说明：AlarmInfoController层
 */
@Controller
@RequestMapping("/alarmInfo")
public class AlarmInfoController {

	@Resource
	private AlarmInfoService alarmInfoService;
	
	@Resource
	private ServerStateService serverStateService;

	@Resource
	private InterferenceQueryService interferenceQueryService;

	/**
	 * 查询历史告警
	 */
	@RequestMapping("/list")
	public void list(@RequestParam(value = "page", required = false) String page, @RequestParam(value = "rows", required = false) String rows, 
			@RequestParam(value = "startTime", required = false) String startTime, @RequestParam(value = "endTime", required = false) String endTime, 
			@RequestParam(value = "siteName", required = false) String siteName, @RequestParam(value = "frontProcessorId", required = false) String frontProcessorId, 
			@RequestParam(value = "alarmTypeIds", required = false) String alarmTypeIds, HttpServletResponse response) throws Exception {
		
		System.out.println("let us start");
		if(alarmTypeIds == null) return;//		map.put("table_name", "history_alarminfo");

		PageBean pageBean = new PageBean(Integer.parseInt(page), Integer.parseInt(rows));
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("database_name", PropertityUtil.NETWORK_MANAGEMENT_DATABASE_NAME);
		map.put("table_name", "alarminfo");
		map.put("start", pageBean.getStart());
		map.put("size", pageBean.getPageSize());
		
		map.put("frontProcessorId", StringUtil.formatLike(frontProcessorId));
		if (startTime != null && !startTime.equals("NaN")) {
			map.put("startTime", startTime);
		}

		if (endTime != null && !endTime.equals("NaN")) {
			map.put("endTime", endTime);
		}
//		if (siteName != null && !siteName.equals("")) {
//			map.put("siteName", siteName);
//		}
		if (siteName != null && !siteName.equals("")&&!siteName.equals("服务器")) {
			List<String> idsList = Arrays.asList(siteName.split(","));
			map.put("siteNames", idsList);
		}
		String errorCode="\"errCode\":1";
		System.out.println(alarmTypeIds);
		if (alarmTypeIds != null && alarmTypeIds.length() > 0) {
			String[] levels = alarmTypeIds.split(",");
			List<Integer> list = new ArrayList<>();
			for (String level : levels) {
				int i = Integer.valueOf(level);
				if (i < 0) continue;
//				if(i==4){
//					//告警选项含有4的时候需要包含4以及15类型的所有数据
//					map.put("errorCodeOther",errorCode);
//				}
//				if(i==15){
//					//增加无上行数据告警错误码作为查询筛选条件
//					map.put("errorCode",errorCode);
//					//上行无数据告警定义为类型15 类型4包含告警类型15
//					i=4;
//				}
				list.add(i);
			}
			//
			if (siteName != null && !siteName.equals("")&&siteName.contains("服务器")) {
				list.add(1);
				list.add(2);
				list.add(3);
			}
			map.put("level", list);
		}else if(siteName != null && !siteName.equals("")&&siteName.contains("服务器")){
			List<Integer> list2 = new ArrayList<>();
			list2.add(1);
			list2.add(2);
			list2.add(3);
			map.put("level1", list2);
		}
		map.put("isHandle",1);
		map.put("isNormal",1);
		List<AlarmInfo> alarmInfoList = alarmInfoService.find(map);
		System.out.println("总告警数"+alarmInfoList.size());
		setupData(alarmInfoList,map);
		
		Long total = alarmInfoService.getTotal(map);
//		Long total = Long.valueOf(alarmInfoList.size());
		JSONObject result = new JSONObject();
		JSONArray jsonArray = JSONArray.fromObject(alarmInfoList);
		result.put("rows", jsonArray);
		result.put("total", total);
		ResponseUtil.write(response, result);
	}

	/**
	 * 查询实时告警
	 */
	@RequestMapping("/listUnhandle")
	public void listUnhandle(@RequestParam(value = "page", required = false) String page, @RequestParam(value = "rows", required = false) String rows, 
			@RequestParam(value = "startTime", required = false) String startTime, @RequestParam(value = "endTime", required = false) String endTime, 
			@RequestParam(value = "siteName", required = false) String siteName, @RequestParam(value = "isHandle", required = false) String isHandle, 
			@RequestParam(value = "frontProcessorId", required = false) String frontProcessorId, 
			@RequestParam(value = "alarmTypeIds", required = false) String alarmTypeIds, AlarmInfo s_alarmInfo, HttpServletResponse response)
		throws Exception {
		if(isHandle == null) return;
		
		PageBean pageBean = new PageBean(Integer.parseInt(page), Integer.parseInt(rows));
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("database_name", PropertityUtil.NETWORK_MANAGEMENT_DATABASE_NAME);
		map.put("table_name", "alarminfo");
		map.put("start", pageBean.getStart());
		map.put("size", pageBean.getPageSize());
		System.out.println("isHandle====="+isHandle);
		if (!isHandle.equals("6")&& !isHandle.equals("7")) {
			if(isHandle.equals("0")){
//				未确认未清除
				map.put("isHandle","0");
				map.put("isNormal","0");
			}
			if(isHandle.equals("1")){
//				已确认未清除
				map.put("isHandle","1");
				map.put("isNormal","0");
			}
			if(isHandle.equals("2")){
//				未确认已清除
				map.put("isHandle","0");
				map.put("isNormal","1");
			}
			if(isHandle.equals("3")){
//				未确认已清除,已确认未清除
                map.put("isHandle1",3);
			}
			if(isHandle.equals("4")){
//				未确认已清除,未确认未清除
				map.put("isHandle2",4);
			}
			if(isHandle.equals("5")){
//				未确认未清除,已确认未清除
				map.put("isHandle3",5);
			}
		}
        map.put("isrealtime",1);
		map.put("frontProcessorId", StringUtil.formatLike(frontProcessorId));
		if (startTime != null && !startTime.equals("NaN")) {
			map.put("startTime", startTime);
		}
		if (endTime != null && !endTime.equals("NaN")) {
			map.put("endTime", endTime);
		}
		if (siteName != null && !siteName.equals("")&&!siteName.equals("服务器")) {
			List<String> idsList = Arrays.asList(siteName.split(","));
			map.put("siteNames", idsList);
		}
		//System.out.println(alarmTypeIds);
//		String errorCode="\"errCode\":1";
		if (alarmTypeIds != null && alarmTypeIds.length() > 0) {
			String[] levels = alarmTypeIds.split(",");
			List<Integer> list = new ArrayList<>();
			for (String level : levels) {
				int i = Integer.valueOf(level);
				if (i < 0) continue;
				list.add(i);
			}
			//下拉框增加服务器选项 （增加查询告警类型1，2，3的记录）
			if (siteName != null && !siteName.equals("")&&siteName.contains("服务器")) {
				list.add(1);
				list.add(2);
				list.add(3);
			}
			map.put("level", list);
		}else if(siteName != null && !siteName.equals("")&&siteName.contains("服务器")){
			List<Integer> list = new ArrayList<>();
			list.add(1);
			list.add(2);
			list.add(3);
			map.put("level1", list);
		}
		
		List<AlarmInfo> alarmInfoList = alarmInfoService.find(map);
		setupData(alarmInfoList,map);
		Long total = alarmInfoService.getTotal(map);
		JSONObject result = new JSONObject();
		JSONArray jsonArray = JSONArray.fromObject(alarmInfoList);
		result.put("rows", jsonArray);
		result.put("total", total);
		ResponseUtil.write(response, result);
	}

	private void setupData(List<AlarmInfo> alarmInfoList, Map<String, Object> map) {
		//for (AlarmInfo alarmInfo : alarmInfoList)
		for (int i = alarmInfoList.size() - 1; i >= 0; i--) {
			AlarmInfo alarmInfo = alarmInfoList.get(i);
			if (alarmInfo.getAlarmType() == 1 || alarmInfo.getAlarmType() == 2 || alarmInfo.getAlarmType() == 3) {
				alarmInfo.setAlarmObjectType("服务器");
				alarmInfo.setAlarmObjectInfo("空口监测服务器");
				if (!alarmInfo.getAlarmDetails().contains("serverId")) continue;
				
				String serverId = JsonUtil.getJsonObjectValue("serverId", alarmInfo.getAlarmDetails());
				Map<String, Object> sMap = new HashMap<>();
				sMap.put("serverId", serverId);
				//System.out.println(sMap);
				List<Serverinfo> serverinfo = serverStateService.getServer(sMap);
				//System.out.println(serverinfo);
				if (serverinfo != null && serverinfo.size() > 0)
					alarmInfo.setAlarmObjectInfo(serverinfo.get(0).getServerName() + "空口监测服务器");
			} else {
				//前置机网络连接告警
				alarmInfo.setAlarmObjectType("空口前置机");
				String siteName = alarmInfo.getSiteName();
				Integer frontId = alarmInfo.getFrontProcessorId();
				if (siteName != null && siteName.length() > 0 && frontId != null && frontId > 0) {
					alarmInfo.setAlarmObjectInfo(siteName + ": " + frontId);
				} else if(frontId != null && frontId > 0) {
					Map<String, Object> map1 = new HashMap<String, Object>();
					map1.put("frontId",frontId);
					map1.put("table_name","bs_info");
					String bs_name=interferenceQueryService.get_bs_name(map1);
					alarmInfo.setAlarmObjectInfo(bs_name + ": " + frontId);
				}else {
					alarmInfo.setAlarmObjectInfo(String.valueOf(frontId));
				}
				String errorcode="\"errCode\":1";
				if(alarmInfo.getAlarmType() ==4 &&alarmInfo.getAlarmDetails().contains(errorcode)){
					alarmInfo.setAlarmType(15);
				}
			}
		}
	}

	/**
	 * 导出AlarmInfo
	 */
	@RequestMapping("/export")
	public void export(@RequestParam(value = "alarmInfoIds") String ids, @RequestParam(value = "realtime") int realtime, HttpServletResponse response) throws Exception {

		Map<String, Object> map = new HashMap<String, Object>();
		map.put("database_name", PropertityUtil.NETWORK_MANAGEMENT_DATABASE_NAME);
		Workbook wb = new HSSFWorkbook();

		if (realtime == 1) { // 实时告警

			map.put("table_name", "alarminfo");
			String headers[] = { "告警编号", "告警级别", "告警对象类型", "告警对象标识", "告警原因", "首次发生时间", "最近发生时间", "发生次数","清除时间","确认时间","确认人", "备注" };
			if (ids != null && !ids.equals("null") && !ids.equals("")) {
				List<String> idsList = Arrays.asList(ids.split(","));
				map.put("alarmInfoIds", idsList);
				List<AlarmInfo> alarmInfoList = alarmInfoService.findByIds(map);
				setupData(alarmInfoList,map);
				ExcelUtil.fillExcelData_AlarmInfo(alarmInfoList, wb, headers);
				ResponseUtil.export(response, wb, "实时告警信息" + FormatDate.formatDate() + ".xls");
			} else {
				map.put("alarmInfoIds", null);
				List<AlarmInfo> alarmInfoList = alarmInfoService.findByIds(map);
				setupData(alarmInfoList,map);
				ExcelUtil.fillExcelData_AlarmInfo(alarmInfoList, wb, headers);
				ResponseUtil.export(response, wb, "实时告警信息" + FormatDate.formatDate() + ".xls");
			}

		} else { // 历史告警
			String headers[] = { "告警编号", "告警级别", "告警对象类型", "告警对象标识", "告警原因", "首次发生时间", "最近发生时间", "发生次数","清除时间","确认时间","确认人", "备注" };
//			map.put("table_name", "history_alarminfo");
			map.put("table_name", "alarminfo");
			if (ids != null && !ids.equals("null") && !ids.equals("")) {
				List<String> idsList = Arrays.asList(ids.split(","));
				map.put("alarmInfoIds", idsList);
				List<AlarmInfo> alarmInfoList = alarmInfoService.findByIds(map);
				setupData(alarmInfoList,map);
				ExcelUtil.fillExcelData_HistoryAlarmInfo(alarmInfoList, wb, headers);
				ResponseUtil.export(response, wb, "历史告警信息" + FormatDate.formatDate() + ".xls");
			} else {
				map.put("alarmInfoIds", null);
				List<AlarmInfo> alarmInfoList = alarmInfoService.findByIds(map);
				setupData(alarmInfoList,map);
				ExcelUtil.fillExcelData_HistoryAlarmInfo(alarmInfoList, wb, headers);
				ResponseUtil.export(response, wb, "历史告警信息" + FormatDate.formatDate() + ".xls");
			}
		}
	}
	
	/**
	 * 导出所有页AlarmInfo
	 */
	@RequestMapping("/exportQuery")
	public void exportQuery(@RequestParam(value = "startTime", required = false) String startTime, @RequestParam(value = "endTime", required = false) String endTime, 
			@RequestParam(value = "frontId", required = false) String frontId, @RequestParam(value = "alarmTypeIds", required = false) String alarmTypeIds, 
			@RequestParam(value="realtime",required=false)int realtime,@RequestParam(value="isHandle",required=false)String isHandle,HttpServletResponse response) throws Exception {

		Workbook wb = new HSSFWorkbook();
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("database_name", PropertityUtil.NETWORK_MANAGEMENT_DATABASE_NAME);
		
		if (frontId != null && frontId.trim().length() > 0) {
			
			String[] subdistrict = frontId.split(",");
			String[] frontID = new String[subdistrict.length];
			
			for (int i = 0; i < subdistrict.length; i++) {
				if (subdistrict[i].trim().length() < 1) continue;
				map.put("frontId", subdistrict[i]);
				map.put("table_name","bs_info");
				frontID[i] = alarmInfoService.get_frontId(map);
			}
			List<String> subList = Arrays.asList(frontID);
			map.put("district", subList);
			System.out.println(map);
		}
//		if (isHandle != null && !isHandle.equals("NaN")) {
//			if(isHandle.equals("是")) {
//				map.put("isHandle", 1);
//			} else if(isHandle.equals("否")) {
//				map.put("isHandle", 0);
//			}
//		}

//		String errorCode="\"errCode\":1";
		if (alarmTypeIds != null && alarmTypeIds.length() > 0) {
			String[] levels = alarmTypeIds.split(",");
			List<Integer> list = new ArrayList<>();
			for (String level : levels) {
				int i = Integer.valueOf(level);
				if (i < 0) continue;
				list.add(i);
			}
			map.put("level", list);
		}
		if (startTime != null && !startTime.equals("NaN")) {
			map.put("startTime", startTime);
		}
		if (endTime != null && !endTime.equals("NaN")) {
			map.put("endTime", endTime);
		}

		if (realtime == 1) { // 实时告警
			map.put("table_name", "alarminfo");
			map.put("isrealtime",1);
			String headers[] = { "告警编号", "告警级别", "告警对象类型", "告警对象标识", "告警原因", "首次发生时间", "最近发生时间", "发生次数","清除时间","确认时间","确认人", "备注" };
			List<AlarmInfo> alarmInfoList = alarmInfoService.find(map);
			System.out.println(alarmInfoList.size());
			setupData(alarmInfoList,map);
			ExcelUtil.fillExcelData_AlarmInfo(alarmInfoList, wb, headers);
			ResponseUtil.export(response, wb, "实时告警信息" + FormatDate.formatDate() + ".xls");
		} else { // 历史告警
			map.put("isHandle",1);
			map.put("isNormal",1);
			map.put("table_name", "alarminfo");
			String headers[] = { "告警编号", "告警级别", "告警对象类型", "告警对象标识", "告警原因", "首次发生时间", "最近发生时间", "发生次数","清除时间","确认时间","确认人", "备注" };
			List<AlarmInfo> alarmInfoList = alarmInfoService.find(map);
			setupData(alarmInfoList,map);
			System.out.println(alarmInfoList);
			ExcelUtil.fillExcelData_HistoryAlarmInfo(alarmInfoList, wb, headers);
			ResponseUtil.export(response, wb, "历史告警信息" + FormatDate.formatDate() + ".xls");
		}
	}
	
	public static String converttime(String s)
    {
    	if (s == null || s.length() < 1 || s.trim().length() < 1) return "";
    	String result;
    	SimpleDateFormat simpleDateformat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss SSS");
		long It=new Long(s);
		Date date=new Date(It);
		result = simpleDateformat.format(date);
		return result;
    }
	/**
	 * 用模板导出AlarmInfo
	 */
	@RequestMapping("/exportByTemplate")
	public void exportByTemplate(@RequestParam(value = "alarmInfoIds") String ids, HttpServletResponse response) throws Exception {
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("database_name", PropertityUtil.NETWORK_MANAGEMENT_DATABASE_NAME);
		map.put("table_name", "history_alarminfo");
		
		if (ids != null && !ids.equals("null") && !ids.equals("")) {
			List<String> idsList = Arrays.asList(ids.split(","));
			map.put("alarmInfoIds", idsList);

			List<AlarmInfo> alarmInfoList = alarmInfoService.findByIds(map);
			try {
				Workbook wb = ExcelUtil.fillExcelDataWithTemplate_AlarmInfo(alarmInfoList, "alarmInfoExportTemplate.xls");
				ResponseUtil.export(response, wb, "利用模版导出excel" + FormatDate.formatDate() + ".xls");
			} catch (Exception e) {
				e.printStackTrace();
			}
		} else {
			map.put("alarmInfoIds", null);
			List<AlarmInfo> alarmInfoList = alarmInfoService.findByIds(map);
			try {
				Workbook wb = ExcelUtil.fillExcelDataWithTemplate_AlarmInfo(alarmInfoList, "alarmInfoExportTemplate.xls");
				ResponseUtil.export(response, wb, "利用模版导出excel" + FormatDate.formatDate() + ".xls");
			} catch (Exception e) {
				e.printStackTrace();
			}
		}
	}

	/**
	 * 添加或者修改AlarmInfo
	 * 
	 * @param
	 * @param response
	 * @param flag 1 添加 2修改
	 */
	@RequestMapping("/save")
	public void save(@RequestParam(value = "alarmInfoIds") String alarmInfoIds, @RequestParam(value = "alarmTypes") String alarmTypes, @RequestParam(value = "isHandle") String isHandle, 
			@RequestParam(value = "flag") int flag, @RequestParam(value = "comfirmer") String comfirmer, AlarmInfo alarmInfo, HttpServletResponse response) throws Exception {
		int resultTotal = 0; // 操作的记录条数
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("database_name", PropertityUtil.NETWORK_MANAGEMENT_DATABASE_NAME);
		map.put("isHandle", 1);
//		map.put("isNormal", 2);
		System.out.println("comfirmer======"+comfirmer);
		map.put("comfirmTime", System.currentTimeMillis());
		map.put("comfirmer",comfirmer);
		String[] idsStr = alarmInfoIds.split(",");
		String[] alaTypes = alarmTypes.split(",");
		for (int i = 0; i < idsStr.length; i++) {
			map.put("alarmInfoId", idsStr[i]);
			System.out.println("alarmInfoId=="+idsStr[i]);
			//前端接收告警类型为15(告警类型数据库不存在仅作前端显示使用)时默认转化为告警类型4
//			System.out.println("alaTypes[i]==="+alaTypes[i].trim());
			if(alaTypes[i].equals("15")){
				map.put("alarmType","4");
			}else{
				map.put("alarmType", alaTypes[i]);
			}
			if (flag == 1) {

			} else {
				map.put("table_name", "alarminfo");
				resultTotal = alarmInfoService.updateAlarmInfo(map);
				//System.out.println(map);
				//System.out.println(resultTotail);
				//同步更新历史告警表
//				map.put("table_name", "history_alarminfo");
//				resultTotal = alarmInfoService.updateAlarmInfo(map);
				//System.out.println(map);
				//System.out.println(resultTotal);
			}
		}
		JSONObject result = new JSONObject();
		if (resultTotal >= 0) {
			result.put("success", true);
		} else {
			result.put("success", false);
		}
		ResponseUtil.write(response, result);

	}

	public static String removeType(int value) {
		if (value == 1) {
			return "自动解除";
		} else if (value == 2) {
			return "手动解除";
		}
		return "";
	}

	public static String formatAlarmClass(int value) {
		if (value == 1 || value == 2 || value == 3 || value == 7 || value == 8 || value == 9) {
			return "一般告警";
		}
		return "紧急告警";
	}

	public static String formatAlarmType(int value) {
		
		if(value==1){
			return "服务器CPU使用率告警";
		}else if(value==2){
			return "服务器内存使用率告警";
		}else if(value==3){
			return "服务器硬盘使用率告警";
		}else if(value==4){
			return "前置机故障";
		}else if(value==5){
			return "前置机掉电重启";
		}else if(value==6){
			return "丢包率告警";
		}else if(value==7){
			return "前置机CPU使用率告警";
		}else if(value==8){
			return "前置机内存使用率告警";
		}else if(value==9){
			return "前置机硬盘使用率告警";
		}else if(value==10){
			return "前置机网络连接告警";
		}else if(value==11){
			return "无频谱数据告警";
		}else if(value==12) {
			return "GPRS数据中断告警";
		}else if (value == 13) {
			return "外网强信号风险";
		}else if (value == 14) {
			return "外网翻频风险";
		}else if (value == 15) {
			return "上行无数据告警";
		}else if (value == 20) {
			return "频谱数据入库异常告警";
		}else if (value == 21) {
			return "电路域数据入库异常告警";
		}
		
		return String.valueOf(value);
	}

	/**
	 * 查询所有前置机 下拉框用到
	 */
	@RequestMapping("/frontBaseName")
	public void groupComboList(HttpServletResponse response) throws Exception {
		//Map<String, Object> map = new HashMap<String, Object>();
		JSONArray jsonArray = new JSONArray();
		JSONObject jsonObject = new JSONObject();
		
		JSONArray jsonArray1 = new JSONArray();
		JSONObject jsonObject1 = new JSONObject();
		List<String> bs_names = alarmInfoService.get_bs_names();
//		bs_names.add("服务器");
		for (int i = 0; i < bs_names.size(); i++) {
			jsonObject.put("id", i);
			jsonObject.put("name", bs_names.get(i));
			jsonObject.put("text", bs_names.get(i));
			jsonArray.add(jsonObject);
		}
		jsonObject1.put("id", 1000);
		jsonObject1.put("name", "全选");
		jsonObject1.put("text", "全选");
		jsonObject1.put("children", jsonArray);
		jsonArray1.add(jsonObject1);
		ResponseUtil.write(response, jsonArray1);

	}

	/**
	 * 查询AlarmInfo总数
	 */
	@RequestMapping("/getTotal")
	public void getTotal(@RequestParam(value = "lastTotal") Integer lastTotal, HttpServletResponse response) throws Exception {
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("database_name", PropertityUtil.NETWORK_MANAGEMENT_DATABASE_NAME);
		map.put("table_name", "alarminfo");
		Integer total = alarmInfoService.getTotal(map).intValue();
		Integer num = total - lastTotal;
		List<AlarmInfo> alarmInfoList = new ArrayList<AlarmInfo>();
		if (num > 0 && lastTotal > 0) {
			map.put("start", 0);
			map.put("size", num);
			alarmInfoList = alarmInfoService.find(map);
		}
		Map<String, Object> map1 = new HashMap<String, Object>();
		//for (AlarmInfo alarmInfo : alarmInfoList)
		for (int i = alarmInfoList.size() - 1; i >= 0; i--) {
			AlarmInfo alarmInfo = alarmInfoList.get(i);
			String errorcode="\"errCode\":1";
			if(alarmInfo.getAlarmType() ==4 &&alarmInfo.getAlarmDetails().contains(errorcode)){
				alarmInfo.setAlarmType(15);
			}
		}
		JSONObject result = new JSONObject();
		JSONArray jsonArray = JSONArray.fromObject(alarmInfoList);
		result.put("rows", jsonArray);
		result.put("total", total);
		ResponseUtil.write(response, result);

	}
}
